package polymorphicdemo;

public class Person {
    String name;
    int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    public String printInfo(Animal a) {
        String wuzhong = a instanceof Dog ? "狗" : "猫";
        return "年龄为" + age + "岁的" + name + "养了一只"+a.getColor() + a.getAge()+"岁的"+ wuzhong;
    }
    public void keepPet(Animal a,String food){
        System.out.println(printInfo(a));
        a.eat(a,food);
    }
}
